﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css" />
        <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
        <script type="text/javascript" src="/js/main_list.js"></script>
        <script language="javascript" type="text/javascript">
            //保存成功的提示信息
            function showResult() {
                showResultDiv(true);
                window.setTimeout("showResultDiv(false);", 3000);
            }
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }
        </script>
    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="/login.html">[退出]</a>
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">                        
            <ul id="menu">
                <li><a href="/index.html" class="index_off"></a></li>
                <li id="liBro" style="display: none;"></li>
            </ul>            
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <div id="main">            
            <!--保存操作后的提示信息：成功或者失败-->
            <div id="save_result_info" class="save_success">保存成功！</div><!--保存失败，数据并发错误！-->

            <form id="form" action="/info/infoModify" method="post" class="main_form">

            </form>  
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>            
            <p>版权所有(C)云科技有限公司 </p>
        </div>
    </body>


<script>
    $(() => {

        $.get("/info/pusher", resp => {

            if (resp.message === 'OK') {

                let i = resp.data;

                console.log(i.adminId);
                console.log(i.adminCode);
                console.log(i.password);
                console.log(i.adminName);
                console.log(i.telephone);
                console.log(i.email);
                console.log(i.enrolldate);
                console.log(i.allRole);

                let form = $('#form');

                let div01 = $('<div class="text_info clearfix"><span>管理员账号：</span></div>');
                let div02 = $('<div class="input_info"><input type="text" name="adminCode" readonly="readonly" class="readonly" value="' + i.adminCode + '" /></div>');

                let div03 = $('<div class="text_info clearfix"><span>角色：</span></div>');
                let div04 = $('<div class="input_info"><input type="text" readonly="readonly" class="readonly width400" value="' + i.allRole + '" /></div>');

                let div05 = $('<div class="text_info clearfix"><span>姓名：</span></div>');
                let div06 = $('<div class="input_info"><input type="text" id="name_text" name="adminName" value="' + i.adminName + '" /><span class="required">*</span></div>');

                let div07 = $('<div class="text_info clearfix"><span>电话：</span></div>');
                let div08 = $('<div class="input_info"><input type="text" name="telephone" class="width200" value="' + i.telephone + '" /><span class="required">*</span></div>');

                let div09 = $('<div class="text_info clearfix"><span>Email：</span></div>');
                let div10 = $('<div class="input_info"><input type="text" name="email" class="width200" value="' + i.email + '" /><span class="required">*</span></div>');

                let div11 = $('<div class="text_info clearfix"><span>创建时间：</span></div>');
                let div12 = $('<div class="input_info"><input type="text" readonly="readonly" class="readonly" value="' + i.enrolldate + '"/></div>');

                let div13 = $('<div class="button_info clearfix"><input type="submit" value="保存" class="btn_save btn_sub" /><input type="button" value="取消" class="btn_save btn_cancel" /></div>');

                form.append(div01);
                div01.after(div13).after(div12).after(div11).after(div10).after(div09).after(div08).after(div07).after(div06).after(div05).after(div04).after(div03).after(div02);

            }

        })

// 取消按钮的点击事件,点击取消按钮,跳转到主页.
        $("body").on("click", "input.btn_cancel", function () {
           window.location.href="/index.html";
        })


        $("body").on("click", "input.btn_sub", function () {
            // 判断名字不能为空
            let name_text = $('#name_text').val();
            if (name_text == null || name_text == ''){
                alert('名字不能为空')
                return false
            }
            // 判断电话号码不能为空
            let telephone_text= $('input[name="telephone"]').val()
            if (telephone_text == null || telephone_text == ''){
                alert('电话号码不能为空')
                return false
            }
            // 判断电话号码的格式是否正确
            let regex1 =/^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}$/
            if (!regex1.test(telephone_text)){
                alert('手机号码格式不正确')
                return false
            }

            // 判断邮箱地址不能为空
            let email_text= $('input[name="email"]').val()
            if (email_text == null || email_text == ''){
               alert('邮箱地址不能为空')
                return false
            }
            let regex2 = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/
            if (!regex2.test(email_text)){
                alert('邮箱的格式不正确')
                return false
            }

            showResult();
        })

    })



</script>



</html>
